﻿using Autofac;
using Autofac.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace QuartzServiceApp
{
    public class AutofacHelper
    {
        //private static readonly ContainerBuilder builder;
        public static IEnumerable<IJob> Jobs { get; set; }
        /// <summary>
        /// AutoFac注册全局Job
        /// </summary>
        static AutofacHelper()
        {
            //builder = new ContainerBuilder();
            //builder
            //    .RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
            //    .AsImplementedInterfaces()
            //    .AsSelf();
            //var container = builder.Build();
            //Jobs = container.Resolve<IEnumerable<IJob>>();

        }
        /// <summary>
        /// 获取IJob
        /// </summary>
        /// <param name="jobName"></param>
        /// <returns></returns>
        public static Type GetAssemlyJobs(IServiceProvider autofacServiceProvider, string jobName)
        {
            Jobs = autofacServiceProvider.GetServices<IJob>();
            return Jobs?.FirstOrDefault(o => o.GetType().Name.ToLower() == jobName.Trim().ToLower())?.GetType();
        }
    }
}
